﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Vit.Web;
using Vit.Web.Models;
using Vit.Web.Providers;
using Vit.Web.Mvc.Results;
using Vit.Web.Helpers;

namespace Vit.AdminModule.Areas.Admin.Controllers
{
    [Authorize]
    public class SiteController : Vit.Web.Mvc.Controllers.ControllerBase
    {
        [HttpGet]
        public ActionResult Index()
        {
            ViewData.Model = PortalContext.Current.Portal.Sites;
            return View();
        }

        [HttpGet]
        public ActionResult Create()
        {
            ViewData.Model = new WebSite();
            return View("DataCreate");
        }

        [HttpPost]
        public ActionResult Create(WebSite site)
        {
            bool result = PortalContext.Current.Portal.AddSite(site);
            ViewData.Model = site;
            ViewBag.Message = "保存成功";
            return Refresh();
        }

        [HttpGet]
        public ActionResult Edit(string id)
        {
            ViewData.Model = PortalContext.Current.Portal.Sites.FirstOrDefault(o => o.ID == id);
            return View("DataEdit");
        }

        [HttpPost]
        public ActionResult Edit(WebSite site)
        {
            bool result = PortalContext.Current.Portal.UpdateSite(site);
            ViewData.Model = site;
            ViewBag.Message = "保存成功";
            return Refresh();
        }

        [HttpGet]
        public ActionResult Delete(string id)
        {
            bool result = PortalContext.Current.Portal.RemoveSite(id);
            ViewBag.Message = "删除成功";
            return RedirectToAction("Index");
        }
    }
}